package com.damon.dm_mail.util;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * 邮件处理类
 */
public class MailOPerator {

    public static boolean modifyFileContent(File file) {
        List<String> list = null;
        try {
            list = FileUtils.readLines(file, "UTF-8");
            String tmp = null;
//            Iterator<String> iterator = list.iterator();
//            while (iterator.hasNext()) {
//                tmp = iterator.next();
////                if (tmp.contains("-") || tmp.contains("_") || !tmp.contains("@")) {
////                    iterator.remove();
////                }
//                String[] array = tmp.split("\\.");
//                if (array == null || array.length != 2) {
//                    iterator.remove();
//                }
//            }
            for (int i = 0; i < list.size(); i++) {
                tmp = list.get(i);
                String[] array = tmp.split("\t");
                if (array != null || array.length >= 2) {
                    list.set(i,array[0]);
                }
            }
            FileUtils.writeLines(file, "UTF-8", list, false);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        File file = new File("d:\\learn\\111111\\weibo_1.txt");
        modifyFileContent(file);
    }
}
